/*
 * @Description:
 * @Version: 0.0.1
 * @Autor: zhj1214
 * @Date: 2021-11-24 15:10:50
 * @LastEditors: zhj1214
 * @LastEditTime: 2022-01-13 17:45:01
 */
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// 如果编辑器提示 path 模块找不到，则可以安装一下 @types/node -> npm i @types/node -D
import { resolve } from "path";

// https://cn.vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  define: {
    "process.env": process.env,
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"), // 设置 `@` 指向 `src`目录
      "@assets": resolve(__dirname, "src/assets"),
      "@utils": resolve(__dirname, "src/utils"),
      "@components": resolve(__dirname, "src/components"),
      "@views": resolve(__dirname, "src/views"),
      "@store": resolve(__dirname, "src/store"),
    },
  },
  base: "./", // 设置打包路径
  server: {
    port: 23501,
    open: true,
    cors: true, // 允许跨域
    // 设置代理，根据我们项目实际情况配置
    // proxy: 'http://36.133.84.100:7001'   // 代理需要在vite 中配置
    proxy: {
      "^/api": {
        // target: "http://0.0.0.0:7001/",
        target: "http://36.133.84.100:7001",
        changeOrigin: true,
        // ws: true,//websocket支持
        secure: false,
        pathRewrite: {
          "^/api": "/api",
        },
      },
      "^/auth": {
        // target: "http://0.0.0.0:7001/",
        target: "http://36.133.84.100:7001",
        changeOrigin: true,
        // ws: true,//websocket支持
        secure: false,
        pathRewrite: {
          "^/auth": "/auth",
        },
      },
      "^/menu": {
        // target: "http://0.0.0.0:7001/",
        target: "http://36.133.84.100:7001",
        changeOrigin: true,
        // ws: true,//websocket支持
        secure: false,
        pathRewrite: {
          "^/menu": "/menu",
        },
      },
      //   '/api': {
      //     target: 'http://xxx.xxx.xxx.xxx:8000',
      //     changeOrigin: true,
      //     secure: false,
      //     rewrite: (path) => path.replace('/api/', '/')
      //   }
    },
  },
});
